<?php

namespace App\Admin\Pages;

use App\Models\TongOrder;
use App\Models\TongUser;
use App\Models\TongUserProfit;
use Illuminate\Contracts\Support\Renderable;

class MyHomePage implements Renderable
{
    public function render()
    {

        $all_user_num = TongUser::query()->count();
        $today_start = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
        $today_end   = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1;
        $today_money = TongOrder::query()->whereIn('status',[1,3,4,5])->where('is_test',0)->whereBetween('created_at',[date('Y-m-d H:i:s',$today_start),date('Y-m-d H:i:s',$today_end)])->sum('all_order_price');
        $order_num = TongOrder::query()->where('is_test',0)->where('status','!=',0)->count();
        $dai_order_num = TongOrder::query()->where('status','=',1)->where('is_test',0)->count();
        $month_start = date('Y-m-01', strtotime(date("Y-m-d"))); //本月开始时间
        $month_end   = date('Y-m-d', strtotime("$month_start +1 month -1 day")).' 23:59:59'; //本月结束时间
        //总交易额
        $all_money = TongOrder::query()->whereIn('status',[1,3,4,5])->where('is_test',0)->sum('all_order_price');
        $month_monty = TongOrder::query()->whereIn('status',[1,3,4,5])->where('is_test',0)->whereBetween('created_at',[$month_start,$month_end])->sum('all_order_price');
        //总订单数
        $order_month_num = TongOrder::query()->whereBetween('created_at',[$month_start,$month_end])->where('is_test',0)->where('status','!=',0)->count();
        //分销的金额
        $fen_all_money = TongUserProfit::query()->whereIn('type',[2,4,3])->where('symbol',1)->sum('money');
        $fen_month_money = TongUserProfit::query()->whereIn('type',[2,4,3])->whereBetween('created_at',[$month_start,$month_end])->where('symbol',1)->sum('money');
        //提货
        $ti_all_money = TongUserProfit::query()->where('type',10)->where('symbol',1)->sum('money');
        $ti_month_money = TongUserProfit::query()->where('type',10)->whereBetween('created_at',[$month_start,$month_end])->where('symbol',1)->sum('money');
        //用户总余额
        $user_all_money = TongUser::query()->sum('money');
        $user_all_repeat_money = TongUser::query()->sum('repeat_money');
        //$all_order =
//        $company_res = getCompanyRes();
//        $hehuo_res = getHehuoRes();
        $user_line = getUserHistory(7);
        $order_line = getOrderHistory(7);
        return admin_view('admin.dashboard.home',['all_user_num'=>$all_user_num,'today_money'=>$today_money,'order_num'=>$order_num,'dai_order_num'=>$dai_order_num,'user_line'=>$user_line,'order_line'=>$order_line,'all_money'=>$all_money,'month_monty'=>$month_monty,'order_month_num'=>$order_month_num,'fen_all_money'=>$fen_all_money,'fen_month_money'=>$fen_month_money,'ti_all_money'=>$ti_all_money,'ti_month_money'=>$ti_month_money,'user_all_money'=>$user_all_money,'user_all_repeat_money'=>$user_all_repeat_money]);
    }
}
